Add flags to assert lock/cache behavior to Cargo
authorAlex Crichton <alex@alexcrichton.com>
Tue, 28 Jun 2016 17:39:46 +0000 (10:39 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 19 Jul 2016 01:50:20 +0000 (18:50 -0700)
commita504f48026f85c2133b21c82facf982697976ab7
treed68af73eb096b649aaf4ed81f34bb24d73a01556
parentf2cf284b0d574b3fdd3be7bdae5a71d619704c48
Add flags to assert lock/cache behavior to Cargo

If a lock file is generated and some equivalent of `cargo fetch` is run then
Cargo shouldn't ever touch the network or modify `Cargo.lock` until any
`Cargo.toml` later changes, but this often wants to be asserted in some build
environments where it's a programmer error if Cargo attempts to access the
network.

The `--locked` flag added here will assert that `Cargo.lock` does not need to
change to proceed. That is, if `Cargo.lock` would be modified (as it
automatically is by default) this is turned into a hard error instead.

This `--frozen` will not only assert that `Cargo.lock` doesn't change (the same
behavior as `--locked`), but it will also will manually prevent Cargo from
touching the network by ensuring that all network requests return an error.

These flags can be used in environments where it is *expected* that no network
access happens (or no lockfile changes happen) because it has been pre-arranged
for Cargo to not happen. Examples of this include:

* CI for projects want to pass `--locked` to ensure that `Cargo.lock` is up to
  date before changes are checked in.
* Environments with vendored dependencies want to pass `--frozen` as touching
  the network indicates a programmer error that something wasn't vendored
  correctly.

A crucial property of these two flags is that **they do not change the behavior
of Cargo**. They are simply assertions at a few locations in Cargo to ensure
that actions expected to not happen indeed don't happen. Some documentation has
also been added to this effect.

Closes #2111
38 files changed:
src/bin/bench.rs
src/bin/build.rs
src/bin/cargo.rs
src/bin/clean.rs
src/bin/doc.rs
src/bin/fetch.rs
src/bin/generate_lockfile.rs
src/bin/git_checkout.rs
src/bin/init.rs
src/bin/install.rs
src/bin/login.rs
src/bin/metadata.rs
src/bin/new.rs
src/bin/owner.rs
src/bin/package.rs
src/bin/pkgid.rs
src/bin/publish.rs
src/bin/run.rs
src/bin/rustc.rs
src/bin/rustdoc.rs
src/bin/search.rs
src/bin/test.rs
src/bin/uninstall.rs
src/bin/update.rs
src/bin/verify_project.rs
src/bin/yank.rs
src/cargo/core/registry.rs
src/cargo/ops/lockfile.rs
src/cargo/ops/registry.rs
src/cargo/sources/git/utils.rs
src/cargo/sources/registry.rs
src/cargo/util/config.rs
src/doc/faq.md
tests/bad-config.rs
tests/build-auth.rs
tests/overrides.rs
tests/path.rs
tests/registry.rs